//
//  CAPlusButton.m
//  cascade-realm
//
//  Created by QSC on 20/5/24.
//

#import "CAPlusButton.h"
#import "CAVPublishArticleController.h"
#import "CAVPublishForumController.h"
@interface CAPlusButton()
@property (nonatomic,strong)UIControl * bgView;
@end
@implementation CAPlusButton
+ (id)plusButton {
    CAPlusButton *button = [[CAPlusButton alloc] init];
    UIImage *normalButtonImage = [UIImage imageNamed:@"plusButton"];
   
    [button setImage:normalButtonImage forState:UIControlStateNormal];

    button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [button sizeToFit];
    button.frame = CGRectMake(0.0, 0.0, 60, 50);

    
    [button addTarget:button action:@selector(clickPublish) forControlEvents:UIControlEventTouchUpInside];
    return button;
}


- (void)clickPublish{
 
    UIControl * bgView = [UIControl new];
    bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6];
    bgView.frame = [UIScreen mainScreen].bounds;
    self.bgView = bgView;
    [[UIApplication sharedApplication].keyWindow addSubview:bgView];
   
    
    
  
    UIButton * imgaeV = [UIButton new];
    [imgaeV setBackgroundImage:Img(@"add_content") forState:UIControlStateNormal];
    [imgaeV setBackgroundImage:Img(@"add_content") forState:UIControlStateHighlighted];
    [bgView addSubview:imgaeV];
    [imgaeV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView);
        make.width.mas_equalTo(297);
        make.height.mas_equalTo(137);
        make.bottom.equalTo(bgView).offset(-kTabBarHeight - 30);
    }];
  
    
    UIControl * leftBtn = [UIControl new];
    [imgaeV addSubview:leftBtn];
  
    [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(imgaeV);
        make.width.equalTo(imgaeV).multipliedBy(0.4);
        make.height.equalTo(imgaeV).multipliedBy(0.8);
    }];
    [leftBtn addTarget:self action:@selector(articleClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIControl *rightBtn = [UIControl new];
    [imgaeV addSubview:rightBtn];
 
    [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(imgaeV);
        make.width.height.equalTo(leftBtn);
    }];
    [rightBtn addTarget:self action:@selector(forumClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    
   
    [bgView addTarget:self action:@selector(bgClick) forControlEvents:UIControlEventTouchUpInside];
}

+ (CGFloat)constantOfPlusButtonCenterYOffsetForTabBarHeight:(CGFloat)tabBarHeight {
    return IsX ? - 35: -20;
}

- (void)bgClick{
    [self.bgView removeFromSuperview];
}


- (void)articleClick{
    
    UINavigationController * nav = (UINavigationController *) [UIApplication sharedApplication].keyWindow.rootViewController;
   
    [nav pushViewController:[CAVPublishArticleController new] animated:YES];
    
    [self.bgView removeFromSuperview];
}

- (void)forumClick{
    UINavigationController * nav = (UINavigationController *) [UIApplication sharedApplication].keyWindow.rootViewController;

    [nav pushViewController:[CAVPublishForumController new] animated:YES];
    
    [self.bgView removeFromSuperview];
}
@end
